import { NMTopoBaseCommand } from '@app-cad/environments/nextmesh/types/command';

import i18n from '@app-cad/common/utils/i18next';
import { CommandDialog } from '@amcax/base';
import { MsComponent } from '../cmd-common/component';
import { RJSFSchema } from '@rjsf/utils';
import { getNormalsOrIds, Picktip } from '../cmd-common/tools';
import { PickInputRJSFFormat } from '@app-base/common/components/command-form/constants';
const setSchema: RJSFSchema = {
  type: 'object',
  properties: {
    target: {
      type: 'array',
      items: {
        type: 'string',
        enum: [],
      },
      format: PickInputRJSFFormat.MultiPickModel,
      uniqueItems: true,
    },
    param: {
      type: 'number',
      title: '厚度',
    },
  },
};
const extraUiSchema = {
  target: Picktip(true, '体'),
  param: Picktip(false, '请输入厚度', ''),
};
const formatFn = (formData) => {
  const ids = getNormalsOrIds(formData.target, 'id').map((it) => it.id);
  if (formData.param != null && ids.length > 0) {
    return {
      target: ids,
      param: formData.param,
    };
  }
  return null;
};
// formData 参数
export function Command({ onClose, title }) {
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <MsComponent
        onClose={onClose}
        formatParam={formatFn}
        formParams={{
          schemaParams: setSchema,
          extraUiSchema: extraUiSchema,
        }}
        wsApi={'midsurface'}
      />
    </CommandDialog>
  );
}

export const cmdMidsurface: NMTopoBaseCommand = {
  id: 'cmdMidsurface',
  label: 'command.topo.midsurface',
  icon: 'commands/feature/midsurface',
  create: function (label: string, onClose: () => void) {
    return (
      <Command
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
